<?php
class Search extends MY_Controller
{
	function __construct()
	{
		parent::__construct();

		$this->load->model('public/book_model');		
		$this->validation->set_fields($this->book_model->fields); 
		
		$this->data['Title'] = 'Search Results';			
		$this->language = parent::getLang();
	}


	function index()
	{
		$params = array('query' => '', 'for_name' => false, 'lang_only' => false);	
		$params['query'] = $this->input->post('query');
		$params['for_name'] = (isset($_POST['search_name']) && $_POST['search_name'] == true) ? true : false;
		$params['lang_only'] = (isset($_POST['search_lang']) && $_POST['search_lang'] == true) ? $this->language : 'ru';
		
		$result = $this->book_model->searchBook($params);
		$this->data['book_list'] = (!empty($result) && count($result) > 0) ? $result : array();
		//print_r( $this->data['book_list'] );
		$this->data['last_query'] = (isset($_POST['query'])) ? $_POST['query']:'';
		$this->data['search_name'] = $params['for_name'];
		$this->data['lang_only'] = $params['lang_only'];
		$this->renderLayout();
	}
	
	function rating() {
		if(!empty($_REQUEST['id']) && !empty($_REQUEST['mark'])) {
			echo '!'.$this->book_model->updateRating($_REQUEST['id'], $_REQUEST['mark']);
			//echo 'aaaaa';
		} 
		//echo 'aaaaa';
	}
}
?>